<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" import="com.zzty.springmybatis.entity.User"%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet"
	href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
<script
	src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script
	src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ZZTY</title>
<!-- BOOTSTRAP STYLES-->
<link href="../css/bootstrap.css" rel="stylesheet" />

<!-- CUSTOM STYLES-->
<link href="../css/custom.css" rel="stylesheet" />
</head>

<script type="text/javascript">
	
<%-- <%User user = (User) request.getSession().getAttribute("user"); --%>
<%-- 			String img = (String) user.getImg();%> --%>
$(document).ready(function() {
	
	var selfpage = 1;
	var selfmaxPage;
	var Obj1;
	showSelfPage();
	showInSelfTable();

	$("#FirstB").click(function() {
		selfpage = 1;
		showSelfPage();
		showInSelfTable();
	})

	$("#LastB").click(function() {
		if (selfpage == 1) {
			alert("已是第一页");
			return;
		}
		selfpage -= 1;
		showSelfPage();
		showInSelfTable();
	})

	$("#NextB").click(function() {
		if (selfpage == selfmaxPage) {
			alert("已是最后一页");
			return;
		}
		selfpage += 1;
		showSelfPage();
		showInSelfTable();
	})

	$("#FinalB").click(function() {
		selfpage = selfmaxPage;
		showSelfPage();
		showInSelfTable();
	})
	
	function showSelfPage(){
		$.get("../History/getSelfMaxPage", function(result) {
			selfmaxPage = result;
		})
		$("#s1").text(selfpage);
		$("#s2").text(selfmaxPage);
	}
	
	function showInSelfTable() {
		$("#tbody1").empty();
		$.get("../History/getSelfHistory/" + selfpage, function(data) {
			data = JSON.parse(data);
			Obj1 = data;
			$.each(data, function(n, value) {
				var type = value.type;
				var date = value.date;
				var question = value.question;
				var operation = "<button class='showSelfAnswer'>点击详情</button>"
				var opr = "<tr><td>" + type + "</td><td>"+ date + "</td><td style='width: 500px'>"+ question + "</td><td>"+ operation +"</td></tr>";
				$("#tbody1").append(opr);
			})
			$("#table2").show();
		})
	}
	
	$(document).on("click",".showSelfAnswer",function(){
		var date =$(this).parent().parent().children().eq(1).text();
		var id = Obj1[0].userId;
		window.open("../HistoryAnswer.jsp?id=" + id + "&date=" + date + "&operation=selfExam");
	})

	
	
	var teampage = 1;
	var teammaxPage;
	var Obj2;
	showTeamPage();
	showInTeamTable();

	$("#FirstB2").click(function() {
		teampage = 1;
		showTeamPage();
		showInTeamTable();
	})

	$("#LastB2").click(function() {
		if (teampage == 1) {
			alert("已是第一页");
			return;
		}
		teampage -= 1;
		showTeamPage();
		showInTeamTable();
	})

	$("#NextB2").click(function() {
		if (teampage == teammaxPage) {
			alert("已是最后一页");
			return;
		}
		teampage += 1;
		showTeamPage();
		showInTeamTable();
	})

	$("#FinalB2").click(function() {
		teampage = teammaxPage;
		showTeamPage();
		showInTeamTable();
	})
	
	function showTeamPage(){
		$.get("../History/getTeamMaxPage", function(result) {
			teammaxPage = result;
		})
		$("#s3").text(teampage);
		$("#s4").text(teammaxPage);
	}
	
	function showInTeamTable() {
		$("#tbody3").empty();
		$.get("../History/getTeamHistory/" + teampage, function(data) {
			data = JSON.parse(data);
			Obj2 = data;
			$.each(data, function(n, value) {
				var type = value.type;
				var date = value.date;
				var question = value.question;
				var operation = "<button class='showTeamAnswer'>点击详情</button>"
				var opr = "<tr><td>" + type + "</td><td>"+ date + "</td><td style='width: 500px'>"+ question + "</td><td>"+ operation +"</td></tr>";
				$("#tbody3").append(opr);
			})
			$("#table4").show();
		})
	}
	
	$(document).on("click",".showTeamAnswer",function(){
		var date =$(this).parent().parent().children().eq(1).text();
		var id;
		$.each(Obj2,function(n,value){
			if(date == value.date){
				id = value.userId;
			}
		})
		window.open("../HistoryAnswer.jsp?id=" + id + "&date=" + date + "&operation=teamExam");
	})
	
})
</script>
<head>

<meta charset=utf-8>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>ZZTY</title>
<!-- BOOTSTRAP STYLES-->
<link href="../css/bootstrap.css" rel="stylesheet" />

<!-- CUSTOM STYLES-->
<link href="../css/custom.css" rel="stylesheet" />
</head>
<body>
	<div id="wrapper">
		<nav class="navbar navbar-default navbar-cls-top " role="navigation"
			style="margin-bottom: 0">
			<div class="navbar-header">
				<a class="navbar-brand">自在天原</a>
			</div>
			<div
				style="color: white; padding: 15px 50px 5px 50px; float: right; font-size: 16px;">
				<form action="../loginOut.jsp" method="post">
					<button type="submit" class="btn btn-danger">注销</button>
				</form>
			</div>
		</nav>
		<!-- /. NAV TOP  -->
		<nav class="navbar-default navbar-side" role="navigation">
			<div class="sidebar-collapse">
				<ul class="nav" id="main-menu">
					<%-- 					<li class="text-center"><img src="<%=img%>" --%>
					<!-- 						class="user-image img-responsive" /></li> -->

					<li><a href="../StudentPageSkip/index"><i
							class="fa fa-dashboard fa-3x"></i> 主页</a></li>
					<li><a href="../StudentPageSkip/UserInfo"><i class="fa fa-table fa-3x"></i>
							个人信息</a></li>
					<li><a href="../StudentPageSkip/SelfExam"><i class="fa fa-desktop fa-3x"></i>
							今日竞赛</a></li>
					<li><a href="../StudentPageSkip/TeamExam"><i class="fa fa-qrcode fa-3x"></i>
							今日结对</a></li>
					<li><a href="../StudentPageSkip/History"><i
							class="fa fa-bar-chart-o fa-3x"></i> 历史记录</a></li>

					<li><a href="../StudentPageSkip/ChangePassword"><i
							class="fa fa-edit fa-3x"></i> 密码修改 </a></li>



				</ul>

			</div>

		</nav>
		<!-- /. NAV SIDE  -->
		<div id="page-wrapper">
			<div id="page-inner">
				<div class="row">
					<div class="col-md-12">
						<h2>历史纪录</h2>
						<h5></h5>

					</div>
				</div>
				<!-- /. ROW  -->
				<hr />
				<h1>竞赛纪录</h1>
					<div class="row" style="padding: 10px 1000px 0px 20px">

					<div class="table-responsive">
						<table class="table table-striped" id="table2"
							style="text-align: center" hidden>
							<thead>
							</thead>
							<tbody id="tbody2">
								<tr>
									<td style="text-align: center" id="FirstB"><button>首页</button></td>
									<td style="text-align: center" id="LastB"><button>上一页</button></td>
									<td>当前第<span id="s1"></span>/<span id="s2"></span>页
									</td>
									<td style="text-align: center" id="NextB"><button>下一页</button></td>
									<td style="text-align: center" id="FinalB"><button>尾页</button></td>
								</tr>

							</tbody>
						</table>
					</div>
				</div>
				<div class="row" style="padding: 10px 20px 0px 20px">

					<div class="table-responsive">
						<table class="table table-striped" id="table1"
							style="text-align: center">
							<thead>
								<tr>
									<th style="text-align: center">Type</th>
									<th style="text-align: center">Date</th>
									<th style="text-align: center">Question</th>
									<th style="text-align: center">Operation</th>
								</tr>
							</thead>
							<tbody id="tbody1">
							</tbody>
						</table>
					</div>
				</div>

				
				<h1>结对纪录</h1>
				<div class="row" style="padding: 10px 1000px 0px 20px">

					<div class="table-responsive">
						<table class="table table-striped" id="table4"
							style="text-align: center" hidden>
							<thead>
							</thead>
							<tbody id="tbody4">
								<tr>
									<td style="text-align: center" id="FirstB2"><button>首页</button></td>
									<td style="text-align: center" id="LastB2"><button>上一页</button></td>
									<td>当前第<span id="s3"></span>/<span id="s4"></span>页
									</td>
									<td style="text-align: center" id="NextB2"><button>下一页</button></td>
									<td style="text-align: center" id="FinalB2"><button>尾页</button></td>
								</tr>

							</tbody>
						</table>
					</div>
				</div>
				<div class="row" style="padding: 10px 20px 0px 20px">

					<div class="table-responsive">
						<table class="table table-striped" id="table3"
							style="text-align: center">
							<thead>
								<tr>
									<th style="text-align: center">Type</th>
									<th style="text-align: center">Date</th>
									<th style="text-align: center">Question</th>
									<th style="text-align: center">Operation</th>
								</tr>
							</thead>
							<tbody id="tbody3">
							</tbody>
						</table>
					</div>
				</div>
				
			</div>
			<!-- /. PAGE INNER  -->
		</div>


		<!-- /. PAGE WRAPPER  -->
	</div>
	<!-- /. WRAPPER  -->
	<!-- SCRIPTS -AT THE BOTOM TO REDUCE THE LOAD TIME-->
	<!-- JQUERY SCRIPTS -->
	<script src="../js/jquery-1.10.2.js"></script>
	<!-- BOOTSTRAP SCRIPTS -->
	<script src="../js/bootstrap.min.js"></script>
	<!-- METISMENU SCRIPTS -->
	<script src="../js/jquery.metisMenu.js"></script>
</body>
</html>
